package com.novanok.googledocxlstest;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.novanok.googledocxlstest.entidad.Cliente;

import java.util.ArrayList;

public class ListaClienteAdapter extends BaseAdapter {

    ArrayList<Cliente> myList = new ArrayList<Cliente>();
    LayoutInflater inflater;
    Context context;

    public ListaClienteAdapter(Context context, ArrayList<Cliente> myList) {
        this.myList = myList;
        this.context = context;
        inflater = LayoutInflater.from( this.context );
    }

    @Override
    public int getCount() {
        return myList.size();
    }

    @Override
    public Cliente getItem(int arg0) {
        return myList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView( int arg0, View arg1, ViewGroup arg2 ) {
        if ( arg1 == null ) {
            arg1 = inflater.inflate( R.layout.list_item_cliente, arg2, false );
        }

        TextView txtNombre = (TextView)arg1.findViewById(R.id.txtNombre);
        // TextView txtLegajo = (TextView)arg1.findViewById(R.id.txtApellido);

        txtNombre.setText( myList.get(arg0).getApellido() + ", " + myList.get(arg0).getNombre() );
        // txtLegajo.setText(ListaClienteAdapter.this.context.getResources().getString(R.string.apellido) + myList.get(arg0).getApellido());

        return arg1;
    }
}